package com.mrjy.live.bo;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.mrjy.common.dto.ParamsDto;
import com.mrjy.common.dto.ResultDto;
import com.mrjy.common.entity.WisInfo;
import com.mrjy.common.util.HttpUtil;
import com.mrjy.live.dao.IWisInfoDao;

@Service("wisInfoBo")
public class WisInfoBo implements IWisInfoBo {
	@Resource
	private IWisInfoDao wisInfoDao;

	@Override
	public void insertWisInfo(WisInfo wisInfo) {
		// TODO Auto-generated method stub
		wisInfoDao.insert(wisInfo);
	}

	@Override
	public void updateWisInfo(WisInfo wisInfo) {
		wisInfoDao.update(wisInfo);
	}

	@Override
	public WisInfo queryWisInfo(int teacherId) {
		return wisInfoDao.query(teacherId);
	}

	@Override
	public ResultDto onlineUsers(ParamsDto paramsDto) {
		ResultDto resultDto = new ResultDto();
		try {
			String url = "http://api.dms.aodianyun.com/v1/topics/" + paramsDto.getTopic() + "/users";
			Map<String, String> paramsTemp=new HashMap<String, String>();
			paramsTemp.put("skip", paramsDto.getSkip()+"");
			paramsTemp.put("num", paramsDto.getNum()+"");
			String result = HttpUtil.doGet(url,paramsTemp);
			ObjectMapper mapper = new ObjectMapper();
			resultDto = mapper.readValue(result, ResultDto.class);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return resultDto;
	}

}
